﻿using Bible.Core.Interface;
using Bible.Core.Model;
using NUnit.Framework;
using System.Collections.Generic;

namespace Bible.Core.UnitTests.Book_Tests
{
    [TestFixture]
    [Category("Core.Model.Book")]
    [Description("Book constructed with default constructor should")]
    public class Book_constructed_with_default_constructor_should
    {
        [Test]
        [Description(" have a non null Chapters property")]
        public void _have_a_non_null_Chapters_property()
        {
            Assert.That(new Book().Chapters, Is.Not.Null,
                "Book.Chapters should not be null.");
        }

        [Test, Description(" have 0 chapters")]
        public void _have_0_chapters()
        {
            Assert.That(new Book().Chapters, Is.Empty,
                "Book.Chapters should be empty.");
        }

        [Test]
        [Description(" have a non null Title property")]
        public void _have_a_non_null_Title_property()
        {
            Assert.That(new Book().Title, Is.Not.Null,
                "Book.Title should not be null.");
        }

        [Test]
        [Description(" have an empty Title property")]
        public void _have_an_empty_Title_property()
        {
            Assert.That(new Book().Title, Is.Empty,
                "Book.Title should be empty.");
        }
    }

    [TestFixture]
    [Category("Core.Model.Book")]
    [Description("Book constructed with chapters parameter should")]
    public class Book_constructed_with_chapters_parameter_should
    {
        [Test, TestCaseSource("ChapterCountCases")]
        [Description(" have the same Chapters count as the constructor parameter list")]
        public void _have_the_same_Chapters_count_as_the_constructor_parameter_list(int chapterCount)
        {
            var book = CreateBookWithChapters(chapterCount);
            Assert.That(book.Chapters.Count, Is.EqualTo(chapterCount),
                "Book.Chapters should have a count of 1.");
        }

        [Test, TestCaseSource("ChapterCountCases")]
        [Description(" have all Chapters of type Chapter")]
        public void _have_all_Chapters_of_type_Chapter(int chapterCount)
        {
            var book = CreateBookWithChapters(chapterCount);
            foreach (var chapter in book.Chapters)
            {
                Assert.That(chapter, Is.TypeOf<IChapter>(),
                    "All objects in Book.Chapters should be of type Chapter");
            }
        }

        private static int[] ChapterCountCases = new int[] { 1, 149 };

        #region Test Helpers

        private IBook CreateBookWithChapters(int chapterCount)
        {
            var chapters = new List<IChapter>();
            for (int i = 0; i < chapterCount; i++)
            {
                chapters.Add(new Chapter());
            }
            return new Book(chapters);
        }

        #endregion Test Helpers
    }
}